<template>
	<view class="setting_container">
		<view class="cell_row">
			<view class="title">
				数据管理
			</view>
			<view class="cell">
				<view class="col" @click="handleShowSelect(0)">
					<view class="left">
						清除1RM复杂测试基准数据
					</view>
					<view class="right">
						<view class="tn-icon-right"></view>
					</view>
				</view>
				<view class="col" @click="handleShowSelect(1)">
					<view class="left">
						清除1RM记录
					</view>
					<view class="right">
						<view class="tn-icon-right"></view>
					</view>
				</view>
				<view class="col" @click="handleDeleteV0()">
					<view class="left">
						清除所有V0
					</view>
					<view class="right">
						<view class="tn-icon-right"></view>
					</view>
				</view>
			</view>
		</view>
		<view class="cell_row">
			<view class="title">
				账号管理
			</view>
			<view class="cell" @click="handleExitLogin">
				<view class="btn_text">
					退出登录
				</view>

			</view>
		</view>

		<tn-select v-model="showSelect" mode="single" :list="list" @confirm="confirm" safeAreaInsetBottom
			:searchShow="false"></tn-select>
	</view>
</template>

<script setup>
	import {
		deleteBaseData,
		deleteAllTestData,
		deleteAllV0
	} from '@/apis/setting.js'
	export default {
		data() {
			return {
				type: '',
				showSelect: false,
				list: [{
					label: '深蹲',
					value: '深蹲'
				}, {
					label: '卧推',
					value: '卧推'
				}, {
					label: '硬拉',
					value: '硬拉'
				}, ],
				currentCell: null, //当前点击的是那个cell 
			}
		},
		methods: {
			// 确定选择当前模式
			confirm(e) {
				let paramsdata = {
					type: e[0].value,
				}
				uni.showModal({
					title: '确认删除吗？',
					content: '',
					showCancel: true,
					success: (res) => {
						if (res.confirm) {
							if (this.currentCell == 0) {
								deleteBaseData(paramsdata.type).then(res => {
									console.log(res)
									uni.showToast({
										title: res.message,
										icon: 'none'
									})
								})
							} else if (this.currentCell == 1) {
								deleteAllTestData(paramsdata.type).then(res => {
									console.log(res)
									uni.showToast({
										title: res.message,
										icon: 'none'
									})
								})
							}
						}
					}
				})

			},
			// 删除所有V0
			handleDeleteV0() {
				uni.showModal({
					title: '确认删除所有V0吗？',
					content: '',
					showCancel: true,
					success: (res) => {
						if (res.confirm) {
							deleteAllV0().then(res => {
								console.log(res)
								uni.showToast({
									title: res.message || '清除成功',
									icon: 'none'
								})
							})

						}
					}
				})
			},
			// 点击展示select
			handleShowSelect(e) {
				this.showSelect = true
				this.currentCell = e
			},
			// 退出登录
			handleExitLogin() {
				uni.showModal({
					title: '提示',
					content: '确定退出登录吗？',
					showCancel: true,
					confirmText: '确定',
					success: (res) => {
						if (res.confirm) {
							uni.setStorageSync('hashLogin', false)
							uni.setStorageSync('userInfo', {})
							uni.showToast({
								title: '退出成功',
								icon: 'none'
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1000)
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		// background-color: #f2f2f3;
	}

	.setting_container {
		width: 100%;
		padding: 30rpx;
		padding-top: 10rpx;

		.cell_row {
			.title {
				font-size: 26rpx;
				color: rgba(124, 124, 126, 1);
				margin: 20rpx 0;

			}

			.cell {
				border-radius: 20rpx;
				background-color: #fff;

				.btn_text {
					padding: 30rpx 20rpx;
					text-align: center;
					color: rgba(255, 59, 48, 1);
				}

				.col {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 30rpx 20rpx;
					border-bottom: 2rpx solid #dededf;

					.left {}

					.right {}
				}

				.col:last-child {
					border-bottom: none;
				}
			}
		}

	}
</style>